<template>
	<view style="margin-top: 20px;">
		<view class="wrapper_yinhang" v-for="(item,index) in cardlist">
			<view class="one" @click="gotixian(item.card_number,item.card_id)">
				<text style="color: rgba(16, 16, 16, 1);font-size: 18px;text-align: left;font-family: PingFangSC-regular;">{{item.bank_name}}</text>
				<text style="color: rgba(16, 16, 16, 1);font-size: 14px;text-align: left;font-family: PingFangSC-regular;">{{item.card_number}}</text>
			</view>
			<view class="two" @click="todelete(item.card_id)">
				<image src="/static/images/next.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardlist: []
			}
		},
		onLoad() {
			this.toonload()
		},
		onNavigationBarButtonTap(e) {
			if (e.float == 'right') {
				uni.navigateTo({
					url: '/pages/setting/addyinhangka'
				})
			}
		},
		methods: {
			toonload(){
				let _this = this
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/UserCart',
					method: "GET",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					success: (res) => {
						console.log(res);
						if (res.data.status == 200) {
							this.cardlist = res.data.data
						} else {
							uni.showToast({
								title: res.data.msg
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			todelete(id) {
				// console.log(id)
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否删除该银行卡',
					success: function(res) {
						if (res.confirm) {
							let token = uni.getStorageSync("token")
							uni.request({
								url: that.G_base + '/api/UserCart/Del',
								method: "post",
								data: {
									card_id: id
								},
								header: {
									'content-type': 'application/x-www-form-urlencoded',
									'Authori-zation': 'Bearer ' + token
								},
								success: (res) => {
									console.log(res);
									if(res.data.status == 200){
										uni.showToast({
											title:res.data.msg,
											icon:"none"
										})
										that.toonload()
									}
								},
								fail: (err) => {
									console.log(err)
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			test() {
				uni.navigateBack({
					delta: 1
				})
			},
			gotixian(e,id) {
				// console.log(e)
				// console.log(id)
				uni.navigateTo({
					url: "../xiugaiyingangka/xiugaiyingangka?card_number="+e+'&card_id='+id
				})
			}
		},

	}
</script>

<style>
	.wrapper_yinhang {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 10px 20px;
	}

	.wrapper_yinhang .two image {
		width: 20px;
		height: 20px;
	}

	.wrapper_yinhang .one text:nth-child(1) {
		margin-bottom: 5px;
	}

	.wrapper_yinhang .one {
		display: flex;
		flex-direction: column;

	}
</style>
